<template>
	<view class="box">

		<view class="main">
			<view class="add-carplate">
				<view>
					<text>输入车牌</text>
				</view>
				<view class="plate">
					<view class="keyboard-input-control" :class="showCursor[0] ? 'highlight' : ''" style="width: 80rpx;"
						@click="handlleInput(0)">
						<view class="keyboard-input">
							<text>{{ characters[0] }}</text><text class="keyboard-input-cursor"
								v-show="showCursor[0]"></text>
						</view>
					</view>
					<view class="keyboard-input-control" :class="showCursor[1] ? 'highlight' : ''" @click="handlleInput(1)">
						<view class="keyboard-input">
							<text>{{ characters[1] }}</text><text v-show="showCursor[1]"
								class="keyboard-input-cursor"></text>
						</view>
					</view>
					<view class="circle">
						<view></view>
					</view>
					<view class="keyboard-input-control" :class="showCursor[2] ? 'highlight' : ''" @click="handlleInput(2)">
						<view class="keyboard-input">
							<text>{{ characters[2] }}</text><text v-show="showCursor[2]"
								class="keyboard-input-cursor"></text>
						</view>
					</view>
					<view class="keyboard-input-control" :class="showCursor[3] ? 'highlight' : ''" @click="handlleInput(3)">
						<view class="keyboard-input">
							<text>{{ characters[3] }}</text><text v-show="showCursor[3]"
								class="keyboard-input-cursor"></text>
						</view>
					</view>
					<view class="keyboard-input-control" :class="showCursor[4] ? 'highlight' : ''" @click="handlleInput(4)">
						<view class="keyboard-input">
							<text>{{ characters[4] }}</text><text v-show="showCursor[4]"
								class="keyboard-input-cursor"></text>
						</view>
					</view>
					<view class="keyboard-input-control" :class="showCursor[5] ? 'highlight' : ''" @click="handlleInput(5)">
						<view class="keyboard-input">
							<text>{{ characters[5] }}</text><text v-show="showCursor[5]"
								class="keyboard-input-cursor"></text>
						</view>
					</view>
					<view class="keyboard-input-control" :class="showCursor[6] ? 'highlight' : ''" @click="handlleInput(6)">
						<view class="keyboard-input">
							<text>{{ characters[6] }}</text><text v-show="showCursor[6]"
								class="keyboard-input-cursor"></text>
						</view>
					</view>
					<view class="keyboard-input-control green" :class="showCursor[7] ? 'highlight' : ''"
						@click="handlleInput(7)">
						<view class="keyboard-input">
							<text v-if="characters[7]" style=" font-size:40rpx">{{
								characters[7]
							}}</text>
							<text v-else style="font-size:16rpx">
								{{ showCursor[7] ? '' : '新能源' }}
							</text>
							<text v-show="showCursor[7]" class="keyboard-input-cursor"></text>
						</view>
					</view>

				</view>
			</view>
			<view class="list-title">其他加车方式</view>
			<view class="list-layout">

				<view class="content" @click="goToUrl('/pages/user/carChoose')">
					<view>选择品牌车型</view>
					<view class="right-side">
						请选择<u-icon name="arrow-right" size="16"></u-icon>
					</view>
				</view>
			</view>
			<view class="list-layout">
				<view class="title">输入行驶证/VIN码

				</view>
				<view class="ipt-layout">
					<view class="scan">
						<u-icon name="scan" size="30" color="#999"></u-icon>
					</view>
					<u--input type="text"></u--input>

				</view>
			</view>
			<view class="sub-layout">
				<view class="btn">完成</view>
			</view>
		</view>
		<u-keyboard ref="uKeyboard" mode="car" :autoChange="true" :overlay="false" :show="show" @change="handleKeyChange"
			@close="show = false" @confirm="handleConfirm" @backspace='handleBackSpace' @cancel="show = false"></u-keyboard>

	</view>
</template>
<script>

export default {
	data() {
		return {
			characters: ['', '', '', '', '', '', '', ''],
			index: 0,
			show: false,
			showCursor: [true],
			choosecar: false
		}
	},

	methods: {
		afterRead(event) {
			console.log(event)
			this.fileList[0] = event.file.url
		},
		checkTelephone(telephone) {
			var reg = /^[1][3,4,5,7,8][0-9]{9}$/;
			if (!reg.test(telephone)) {
				return false;
			} else {
				return true;
			}
		},
		checkTel() {
			const res = checkTelephone(telNum.value)
			if (!res) {
				uni.showToast({
					icon: 'none',
					title: '请输入正确的手机号码'
				})
			}
		},
		confirmDate(e) {
			const date = new Date(e.value)
			const year = date.getFullYear()
			const month = date.getMonth() + 1
			const day = date.getDate()
			this.date_ = year + '-' + month + '-' + day
			this.show = false
		},
		handlleInput(index) {
			this.show = true;
			this.index = index
			this.$set(this, 'showCursor', []);
			this.$set(this.showCursor, index, true)
		},
		handleKeyChange(val) {
			console.log(this.index)
			let index = this.index
			this.$set(this.characters, index, val)
			if (index < 8) {
				this.handlleInput(index + 1)
			}

		},
		handleConfirm() {
			this.show = false;
			this.$set(this, 'showCursor', []);
			// this.$set(this.showCursor, this.index + 1, true)
		},
		handleBackSpace() {
			this.$set(this.characters, this.index, '')
		}
	}
}
</script>
<style lang="scss" scoped>
.box {
	background-color: #eee;
	height: 100vh;
}

.add-carplate {

	padding: 20rpx;
	background-color: #fff;
	border-radius: 10rpx;
	margin-top: 20rpx;

	.plate {
		padding-top: 20rpx;
		@include flex-center(row, space-between, center);

		.circle {
			width: 10rpx;
			height: 80rpx;
			@include flex-center(row, center, center);

			view {
				width: 8rpx;
				height: 8rpx;
				background-color: #000;
				border-radius: 20rpx;
				font-size: 0;
			}
		}

		.keyboard-input-control {
			width: 50rpx;
			height: 80rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border: 1px solid #eee;
			border-radius: 10rpx;

			&.highlight {
				border: 1px solid red !important;
			}

			&.green {
				background-color: aquamarine;
				border: 1px dashed seagreen;
				color: seagreen;


			}
		}

		.keyboard-input {
			display: flex;
			justify-content: center;
			align-items: center;
			position: relative;
			font-size: 40rpx;
			line-height: 80rpx;
			font-weight: bold;

			&.place-holder {
				font-weight: normal;
			}
		}

		.keyboard-input-cursor {
			height: 40rpx;
			width: 2px;
			background: #000;
			animation: twinkling 1s infinite;
		}

	}
}



.main {
	padding: 0 40rpx;
}

.list-title {
	font-size: 24rpx;
	color: #999;
	margin-top: 20rpx;
}

.list-layout {
	padding: 30rpx 20rpx;
	background-color: #fff;
	border-radius: 10rpx;
	margin-top: 20rpx;

	font-size: 32rpx;

	.content {
		@include flex-center(row, space-between, center);

	}

	.right-side {
		@include flex-center(row, flex-end, center);
		font-size: 28rpx;
		color: #999;
	}

	.title {
		@include flex-center(row, space-between, center);
	}

	.ipt-layout {
		margin-top: 20rpx;
		position: relative;

		.scan {
			position: absolute;
			right: 10rpx;
			top: 8rpx;
		}
	}
}

.sub-layout {
	.btn {
		background-color: red;
		color: #fff;
		padding: 20rpx;
		border-radius: 10rpx;
		text-align: center;
		margin-top: 20rpx;
	}
}
</style>
